<template>
  <div class="elm-edit">
    <elm-page-bb>
      <el-form ref="model" :model="model" size="small" label-width="120px">
        <elm-row>
          <el-form-item label="采购日期" prop="purchase_date">
            <el-date-picker v-model="model.purchase_date"  type="date" value-format="yyyy-MM-dd" style="width: 100%"  ></el-date-picker>
          </el-form-item>
          <el-form-item label="申请部门" prop="department" :rules="[{ required: true, message: '必须填写'}]">
            <elm-org v-model="model.department"></elm-org>
          </el-form-item>
        </elm-row>
        <elm-row>
          <el-form-item label="采购负责人" prop="purchaser_name">
            <elm-ei v-model="model.purchaser_name"></elm-ei>
          </el-form-item>
          <el-form-item label="交货日期" prop="delivery_date">
            <el-date-picker v-model="model.delivery_date"  type="date" value-format="yyyy-MM-dd" style="width: 100%"  ></el-date-picker>
          </el-form-item>
        </elm-row>
        <elm-row>
          <el-form-item label="供应商名称" prop="supplier_name">
            <el-input v-model="model.supplier_name"></el-input>
          </el-form-item>
          <el-form-item label="供应商联系方式" prop="supplier_contact">
            <el-input v-model="model.supplier_contact"></el-input>
          </el-form-item>
        </elm-row>
        <elm-row>
          <el-form-item label="采购金额" prop="purchase_amount" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
            <el-input v-model="model.purchase_amount">
              <template slot="append"><div style="width: 25px;text-align: center;">元</div></template>
            </el-input>
          </el-form-item>
          <el-form-item label="采购订单号" prop="purchase_order_no">
            <el-input v-model="model.purchase_order_no"></el-input>
          </el-form-item>
        </elm-row>
        <el-form-item label="用途/项目名称" prop="purpose">
          <el-input v-model="model.purpose" type="textarea" :rows="2"></el-input>
        </el-form-item>
        <el-form-item label="收货地点" prop="delivery_address">
          <el-input v-model="model.delivery_address" type="textarea" :rows="2"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="notes">
          <el-input v-model="model.notes" type="textarea" :rows="2"></el-input>
        </el-form-item>
        <el-form-item label="资料">
          <elm-upload module_name="biz_wms_purchase_file" :rel_id="model.id" :multiple="true" :limit="10"  list-type="picture" tip=" "></elm-upload>
        </el-form-item>
      </el-form>
      <template #bottom>
        <el-button type="success" size="small" @click="submit">立即保存</el-button>
        <el-button size="small" @click="close">取消</el-button>
      </template>
    </elm-page-bb>
  </div>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      model: {id: elm.newGuid()},
    }
  },
  async created() {
  },
  methods: {

    async submit() {
      await this.$refs["model"].validate();
      var res = await elm.post('/business/wms/purchase/Upsert', this.model);
      if (res == true) {
        this.v('保存成功。')
        this.close();
        this.request.callVue.tablebinding();
      }
      else {
        this.error('保存失败，请稍后尝试。');
      }
    },
  },
}
</script>